import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    count:0
  },
  getters: {

  },
  mutations: {
    add(state){
      state.count++
    },
    addN(state,step){
      state.count += step
    },
    sub(state){
      state.count--
    },
    subN(state,step){
      state.count -= step

    }
  },
  actions: {
    addAsyn(context){
      setTimeout(() => {
        context.commit('add')
      },3000)

    },
    addAsynN(context,step){
      setTimeout(() => {
        context.commit('addN',step)
      },2000)
    },
    subAsyn(context){
      setTimeout(() => {
        context.commit('sub')
      },2000)
    },
    subAsynN(context,step){
      setTimeout(() => {
        context.commit('subN',step)
      },2000)
    }

  },
  modules: {
  },
  getters:{
    showNum(state){
      return '当前最新的数量是：' + state.count
    }

  }
})
